<template>
	<Top-Page v-if="show && list">
		<view class="recommend-dialog">
			<view class="content">
				<view class="title">
					<text class="fs-32">{{ title }}</text>
					<image
						class="close"
						style="width: 40rpx; height: 40rpx"
						src="/static/image/cancel.png"
						mode=""
						@click="close"
					></image>
				</view>
				<view class="list">
					<view class="li" v-for="item in list" @click="toDetail(item.user_id)">
						<view style="display: flex; align-items: center; justify-content: space-between">
							<view style="display: flex; align-items: center">
								<user-avator :src="item.avatar || item.avatar2 || item.avatar3"></user-avator>
								<view style="margin: 0 20rpx; flex: 1">
									<text class="fs-32" style="font-weight: 700">{{ item.realname }}</text>
									<text style="display: block">{{ item.text }}</text>
								</view>
							</view>
							<text class="btn">查看</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</Top-Page>
</template>

<script>
export default {
	name: "recommend-dialog",
	data() {
		return {
			show: false,
			list: [],
			title: "",
		}
	},
	created() {
		this.getList()
	},
	methods: {
		close() {
			this.show = false
		},
		getList() {
			this.$api.friendApi.getPushFriends().then((res) => {
				if (res.code == 0) {
					this.title = res.data.title
					const totalList = []
					console.log(res.data.list)
					for (let key in res.data.list) {
						console.log(key, "value")
						if (res.data.list[key].length) {
							totalList.push(...res.data.list[key])
						}
					}
					this.list = totalList
					if (totalList.length) {
						this.show = true
					}
				}
			})
		},
		toDetail(id) {
			uni.navigateTo({
				url: `/pages/contacts/detail?id=${id}&group_id=group_nearby`,
			})
		},
	},
}
</script>

<style lang="scss">
.recommend-dialog {
	position: fixed;
	// top: 0;
	top: var(--status-bar-height);
	right: 0;
	bottom: 0;
	left: 0;
	background-color: rgba(0, 0, 0, 0.5);
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	.content {
		background-color: #fff;
		width: 80vw;
		border-radius: 20rpx;
		.title {
			position: relative;
			text-align: center;
			padding: 30rpx;
			border-bottom: 2rpx solid #e9e9e9;
			.close {
				position: absolute;
				right: 30rpx;
				top: 30rpx;
			}
		}
		.list {
			height: 50vh;
			overflow-y: scroll;
			.li {
				padding: 30rpx;
				border-bottom: 2rpx solid #f7f7f7;
				border-radius: 20rpx;
				text {
					line-height: 1.5;
					word-break: break-all;
				}
				.btn {
					background-color: #1a66ff;
					color: #fff;
					border-radius: 30rpx;
					padding: 4rpx 20rpx;
					white-space: nowrap;
				}
			}
		}
	}
}
</style>
